HAL WWDG migration: List of applicable concepts

This section provides information about the HAL WWDG applicable architecture concepts.

Concepts for WWDG

Concept

Description

Separation of initialization and configuration functions

  • In HAL2, the HAL_WWDG_Init initializes the HAL WWDG handle and links it to the specified WWDG peripheral instance.

  • In HAL2, there are no configuration structure neither function, the WWDG parameters max/min time are provided in ms/µs/s to the HAL_WWDG_Start function.

Renaming of the handle structure

The handle structure has been renamed to hal_wwdg_handle_t.

Remove MspInit and MspDeInit callbacks

HAL_WWDG_MspInit() and MspInitCallback are no longer available and have been replaced by a user sequence to initializes and configures the WWDG.

Unitary configuration APIs

New APIs are available to get and set WWDG features.

Introduction of HAL user data set/get APIs

Two functions to set and get user data are available: HAL_WWDG_SetUserData(), HAL_WWDG_GetUserData()

Individual callback registration APIs replace global register and unregister functions

The callback registration is handled by specific functions for each WWDG event. These functions are used to register callback functions for different WWDG events.

HAL implementation with LL inline functions

HAL WWDG APIs now rely on LL APIs rather than performing direct register access.

Define statements and enumerations redirected to LL equivalents

HAL WWDG define statements and enumerations are based on LL define statements.

Removal of hardware-related macros in HAL2

All hardware macros have been removed from the HAL WWDG driver, and equivalent services are ensured through the LL APIs.

Revised and optimized HAL state machine

A state machine has been introduced in HAL2, comprising the following states:

  • HAL_WWDG_STATE_RESET

  • HAL_WWDG_STATE_IDLE

  • HAL_WWDG_STATE_ACTIVE

Revised and optimized HAL API status returns

The HAL WWDG functions were updated to return:

  • HAL_INVALID_PARAM: in case of a NULL p_config structure pointer.

  • HAL_ERROR: in case of an error.

  • HAL_TIMEOUT: in case of a user timeout.

  • HAL_BUSY: in case of an ongoing process.

  • HAL_OK: in case of a successfully completed operation.

Replaced TypeDef suffix with _t in type names

All TypeDef parts of the HAL WWDG driver have been removed and replaced by _t.

Replaced nonmodifiable pointers with const keywords

Const keywords have been added to non-modifiable pointers to ensure that either the pointer itself or the data it points to cannot be modified. This enhances code safety and readability, prevents unintended modifications, and renders code more robust and maintainable.

Assertion implementation and usage in HAL1

The parameters and state are checked using ASSERT_DBG_STATE and ASSERT_DBG_PARAM macro.

Split Peripheral Configuration from Start in System HAL Drivers.

The initialization has been split into two functions: one for initialization and one for starting.

Replace Finite Parameter Defines (Including PPP Instances) with Enum Types at HAL Levels.

Finite parameters (including WWDG instances) have been converted into enumerated types (enums) at HAL level. This improves code readability, maintainability, and type safety.

Add HAL_PPP Prefix to All HAL Peripheral APIs (Defines, Macros, Types, and Functions).

All HAL WWDG functions start with HAL_WWDG. All HAL WWDG enums and structs start with hal_wwdg.

Other HAL WWDG Changes

Concept

Consideration

The values for Prescaler, Counter, and Window are derived from the minimum and maximum times.

In HAL1, the user manually calculates the values for prescaler, window, and reload and defines them explicitly. However, in HAL2 these values are automatically derived from the parameters provided to the start function.

  • The minimum time corresponds to Window time.

  • The maximum time corresponds to Reset time.

Configure the WWDG to manage times in seconds (s), milliseconds (ms), and microseconds (µs).

By using the define USE_WWDG_TIME_UNIT (in conf.h file ), the user can configure the WWDG time management.

  • HAL_WWDG_TIME_UNIT_US: WWDG driver time unit in microseconds.

  • HAL_WWDG_TIME_UNIT_MS: WWDG driver time unit in milliseconds.

  • HAL_WWDG_TIME_UNIT_S: WWDG driver time unit in seconds.

This time unit apply to the HAL_WWDG_Start, HAL_WWDG_GetMaxTime, HAL_WWDG_GetMinTime, HAL_WWDG_SetMinTime. It does not apply to the HAL_WWDG_GetStep which always returns the WWDG step in microseconds.